package per.hx.bs.yw.serviceimpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import per.hx.bs.entity.yw.YwLeaveDO;
import per.hx.bs.yw.dao.YwLeaveDao;

import java.util.List;
import java.util.Map;

/**
 * @author HuXing
 * @date 2018/4/20  7:58
 */
@Transactional(rollbackFor = Exception.class)
@RestController
@RequestMapping(value = "yw-service/leave")
public class YwLeaveApiServiceImpl {
    private final
    YwLeaveDao leaveDao;

    @Autowired
    public YwLeaveApiServiceImpl(YwLeaveDao leaveDao) {
        this.leaveDao = leaveDao;
    }

    /**
     * 按条件获取考勤信息
     *
     * @param map 条件
     * @return 考勤信息
     */
    @PostMapping(value = "/leaveList")
    public List<YwLeaveDO> leaveList(@RequestBody Map<String, Object> map) {
        return leaveDao.leaveList(map);
    }


    /**
     * 按条件获取请假申请
     *
     * @param map 条件
     * @return 报销申请
     */
    @PostMapping(value = "/leaveListByMap")
    public List<YwLeaveDO> leaveListByMap(@RequestBody Map<String, Object> map) {
        return leaveDao.selectByMap(map);

    }

    /**
     * 按条件获取考勤信息数量
     *
     * @param map 条件
     * @return 考勤信息数量
     */
    @PostMapping(value = "/leaveCount")
    public int leaveCount(@RequestBody Map<String, Object> map) {
        return leaveDao.leaveCount(map);
    }


    /**
     * 获取请假数据
     *
     * @param id id
     * @return 请假数据
     */
    @GetMapping(value = "/{id}")
    public YwLeaveDO selectOne(@PathVariable("id") Long id) {
        return leaveDao.selectById(id);
    }

    /**
     * 添加请假数据
     *
     * @param leaveDO 插入数据
     * @return 插入id
     */
    @PostMapping
    public Long insert(@RequestBody YwLeaveDO leaveDO) {
        leaveDao.insert(leaveDO);
        return leaveDO.getId();
    }

    /**
     * 修改请假数据
     *
     * @param leaveDO 请假数据
     * @return 差距结果
     */
    @PutMapping
    public Integer update(@RequestBody YwLeaveDO leaveDO) {
        return leaveDao.updateById(leaveDO);
    }

    /**
     * 删除数据
     *
     * @param id id
     * @return 结果
     */
    @DeleteMapping(value = "/{id}")
    public int delete(@PathVariable("id") Long id) {
        return leaveDao.deleteById(id);
    }


}
